<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="agreementid">
      <el-input v-model="dataForm.agreementid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="feetype">
      <el-input v-model="dataForm.feetype" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="periodtype">
      <el-input v-model="dataForm.periodtype" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="dayslimit">
      <el-input v-model="dataForm.dayslimit" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="monthlyday">
      <el-input v-model="dataForm.monthlyday" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="upperlimit">
      <el-input v-model="dataForm.upperlimit" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="exchangeratetype">
      <el-input v-model="dataForm.exchangeratetype" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="exchangeratevalue">
      <el-input v-model="dataForm.exchangeratevalue" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="adminid">
      <el-input v-model="dataForm.adminid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="adminsn">
      <el-input v-model="dataForm.adminsn" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="status">
      <el-input v-model="dataForm.status" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="createdate">
      <el-input v-model="dataForm.createdate" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="updatedate">
      <el-input v-model="dataForm.updatedate" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="summary">
      <el-input v-model="dataForm.summary" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          agreementid: '',
          feetype: '',
          periodtype: '',
          dayslimit: '',
          monthlyday: '',
          upperlimit: '',
          exchangeratetype: '',
          exchangeratevalue: '',
          adminid: '',
          adminsn: '',
          status: '',
          createdate: '',
          updatedate: '',
          summary: ''
        },
        dataRule: {
          agreementid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          feetype: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          periodtype: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          dayslimit: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          monthlyday: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          upperlimit: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          exchangeratetype: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          exchangeratevalue: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          adminid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          adminsn: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          createdate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          updatedate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          summary: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/crm/clientfeesettlements/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.agreementid = data.clientfeesettlements.agreementid
                this.dataForm.feetype = data.clientfeesettlements.feetype
                this.dataForm.periodtype = data.clientfeesettlements.periodtype
                this.dataForm.dayslimit = data.clientfeesettlements.dayslimit
                this.dataForm.monthlyday = data.clientfeesettlements.monthlyday
                this.dataForm.upperlimit = data.clientfeesettlements.upperlimit
                this.dataForm.exchangeratetype = data.clientfeesettlements.exchangeratetype
                this.dataForm.exchangeratevalue = data.clientfeesettlements.exchangeratevalue
                this.dataForm.adminid = data.clientfeesettlements.adminid
                this.dataForm.adminsn = data.clientfeesettlements.adminsn
                this.dataForm.status = data.clientfeesettlements.status
                this.dataForm.createdate = data.clientfeesettlements.createdate
                this.dataForm.updatedate = data.clientfeesettlements.updatedate
                this.dataForm.summary = data.clientfeesettlements.summary
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/crm/clientfeesettlements/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'agreementid': this.dataForm.agreementid,
                'feetype': this.dataForm.feetype,
                'periodtype': this.dataForm.periodtype,
                'dayslimit': this.dataForm.dayslimit,
                'monthlyday': this.dataForm.monthlyday,
                'upperlimit': this.dataForm.upperlimit,
                'exchangeratetype': this.dataForm.exchangeratetype,
                'exchangeratevalue': this.dataForm.exchangeratevalue,
                'adminid': this.dataForm.adminid,
                'adminsn': this.dataForm.adminsn,
                'status': this.dataForm.status,
                'createdate': this.dataForm.createdate,
                'updatedate': this.dataForm.updatedate,
                'summary': this.dataForm.summary
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
